package com.it.schoolbookshop_back.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface MoneyMapper {

    /**
     * 根据用户ID查询余额
     * @param userId 用户ID
     * @return 用户余额
     */
    @Select("SELECT balance FROM users WHERE id = #{userId}")
    Double getBalanceByUserId(@Param("userId") Integer userId);

    /**
     * 更新用户余额
     * @param userId 用户ID
     * @param newBalance 新余额
     * @return 影响的行数
     */
    @Update("UPDATE users SET balance = #{newBalance} WHERE id = #{userId}")
    int updateBalance(@Param("userId") Integer userId, @Param("newBalance") Double newBalance);
}
